{% extends "base.html" %}

{% block content %}
<!-- 多维度分析概览 -->
<div class="section">
    <div class="section-title">🔍 多维度分析概览</div>
    <div class="section-content">
        {% if data.dimension_overview %}
        <div class="stats-cards">
            <div class="stat-card">
                <div class="stat-value">{{ data.dimension_overview.analysis_dimensions | length }}</div>
                <div class="stat-label">分析维度</div>
            </div>
            <div class="stat-card">
                <div class="stat-value">{{ data.dimension_overview.total_data_points | format_number }}</div>
                <div class="stat-label">数据点</div>
            </div>
            <div class="stat-card">
                <div class="stat-value">{{ data.dimension_overview.coverage_rate | format_percentage }}</div>
                <div class="stat-label">数据覆盖率</div>
            </div>
            <div class="stat-card">
                <div class="stat-value {{ 'highlight-good' if data.dimension_overview.overall_score > 0.8 else 'highlight-bad' }}">
                    {{ (data.dimension_overview.overall_score * 100) | round(1) }}分
                </div>
                <div class="stat-label">综合得分</div>
            </div>
        </div>
        {% endif %}
    </div>
</div>

<!-- 区域维度分析 -->
<div class="section">
    <div class="section-title">🌍 区域维度分析</div>
    <div class="section-content">
        {% if data.region_dimension %}
        <table class="data-table">
            <thead>
                <tr>
                    <th>区域名称</th>
                    <th>设备数量</th>
                    <th>工作效率</th>
                    <th>出勤率</th>
                    <th>故障率</th>
                    <th>综合评分</th>
                </tr>
            </thead>
            <tbody>
                {% for region in data.region_dimension %}
                <tr>
                    <td>{{ region.region_name }}</td>
                    <td>{{ region.device_count | format_number }}</td>
                    <td class="{{ 'highlight-good' if region.efficiency > 0.8 else 'highlight-bad' }}">
                        {{ (region.efficiency * 100) | round(1) }}%
                    </td>
                    <td class="{{ 'highlight-good' if region.attendance_rate > 0.8 else 'highlight-bad' }}">
                        {{ (region.attendance_rate * 100) | round(1) }}%
                    </td>
                    <td class="{{ 'highlight-good' if region.failure_rate < 0.1 else 'highlight-bad' }}">
                        {{ (region.failure_rate * 100) | round(1) }}%
                    </td>
                    <td class="highlight-number">{{ region.score | round(1) }}分</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        {% else %}
        <div class="no-data">暂无区域维度数据</div>
        {% endif %}
    </div>
</div>

<!-- 项目维度分析 -->
<div class="section">
    <div class="section-title">📂 项目维度分析</div>
    <div class="section-content">
        {% if data.project_dimension %}
        <table class="data-table">
            <thead>
                <tr>
                    <th>项目名称</th>
                    <th>所属区域</th>
                    <th>设备数量</th>
                    <th>工作强度</th>
                    <th>设备利用率</th>
                    <th>项目状态</th>
                </tr>
            </thead>
            <tbody>
                {% for project in data.project_dimension %}
                <tr>
                    <td>{{ project.project_name }}</td>
                    <td>{{ project.region_name }}</td>
                    <td>{{ project.device_count | format_number }}</td>
                    <td class="{{ 'highlight-good' if project.work_intensity > 0.7 else 'highlight-bad' }}">
                        {{ (project.work_intensity * 100) | round(1) }}%
                    </td>
                    <td class="{{ 'highlight-good' if project.utilization > 0.8 else 'highlight-bad' }}">
                        {{ (project.utilization * 100) | round(1) }}%
                    </td>
                    <td class="{{ 'highlight-good' if project.status == '正常' else 'highlight-bad' }}">
                        {{ project.status }}
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        {% else %}
        <div class="no-data">暂无项目维度数据</div>
        {% endif %}
    </div>
</div>

<!-- 设备类型维度分析 -->
<div class="section">
    <div class="section-title">🔧 设备类型维度分析</div>
    <div class="section-content">
        {% if data.device_type_dimension %}
        <table class="data-table">
            <thead>
                <tr>
                    <th>设备类型</th>
                    <th>数量</th>
                    <th>平均工作时间</th>
                    <th>可靠性指数</th>
                    <th>维护成本</th>
                    <th>投资回报率</th>
                </tr>
            </thead>
            <tbody>
                {% for device_type in data.device_type_dimension %}
                <tr>
                    <td>{{ device_type.type_name }}</td>
                    <td>{{ device_type.count | format_number }}</td>
                    <td class="highlight-number">{{ device_type.avg_work_time | format_duration }}</td>
                    <td class="{{ 'highlight-good' if device_type.reliability > 0.9 else 'highlight-bad' }}">
                        {{ (device_type.reliability * 100) | round(1) }}%
                    </td>
                    <td>{{ device_type.maintenance_cost | format_number }}元</td>
                    <td class="{{ 'highlight-good' if device_type.roi > 1.5 else 'highlight-bad' }}">
                        {{ device_type.roi | round(2) }}
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        {% else %}
        <div class="no-data">暂无设备类型维度数据</div>
        {% endif %}
    </div>
</div>

<!-- 时间维度分析 -->
<div class="section">
    <div class="section-title">⏰ 时间维度分析</div>
    <div class="section-content">
        {% if data.time_dimension %}
        <table class="data-table">
            <thead>
                <tr>
                    <th>时间段</th>
                    <th>工作设备数</th>
                    <th>工作强度</th>
                    <th>峰值利用率</th>
                    <th>效率指数</th>
                </tr>
            </thead>
            <tbody>
                {% for time_slot in data.time_dimension %}
                <tr>
                    <td>{{ time_slot.time_range }}</td>
                    <td>{{ time_slot.active_devices | format_number }}</td>
                    <td class="{{ 'highlight-good' if time_slot.intensity > 0.7 else 'highlight-bad' }}">
                        {{ (time_slot.intensity * 100) | round(1) }}%
                    </td>
                    <td class="{{ 'highlight-good' if time_slot.peak_utilization > 0.8 else 'highlight-bad' }}">
                        {{ (time_slot.peak_utilization * 100) | round(1) }}%
                    </td>
                    <td class="highlight-number">{{ time_slot.efficiency_index | round(2) }}</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        {% else %}
        <div class="no-data">暂无时间维度数据</div>
        {% endif %}
    </div>
</div>

<!-- 关键指标对比 -->
<div class="section">
    <div class="section-title">📈 关键指标对比</div>
    <div class="section-content">
        {% if data.key_metrics_comparison %}
        <div style="margin-bottom: 20px;">
            <h4 style="color: #1f4e79; margin-bottom: 10px;">核心KPI对比</h4>
            <table class="data-table">
                <thead>
                    <tr>
                        <th>指标名称</th>
                        <th>当前值</th>
                        <th>目标值</th>
                        <th>完成度</th>
                        <th>趋势</th>
                    </tr>
                </thead>
                <tbody>
                    {% for metric in data.key_metrics_comparison %}
                    <tr>
                        <td>{{ metric.metric_name }}</td>
                        <td class="highlight-number">{{ metric.current_value }}</td>
                        <td>{{ metric.target_value }}</td>
                        <td class="{{ 'highlight-good' if metric.completion_rate > 0.8 else 'highlight-bad' }}">
                            {{ (metric.completion_rate * 100) | round(1) }}%
                        </td>
                        <td class="{{ 'highlight-good' if metric.trend == '上升' else 'highlight-bad' }}">
                            {{ metric.trend }}
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        {% else %}
        <div class="no-data">暂无关键指标数据</div>
        {% endif %}
    </div>
</div>

<!-- 多维度排名 -->
<div class="section">
    <div class="section-title">🏆 多维度综合排名</div>
    <div class="section-content">
        {% if data.multi_dimension_rankings %}
        <div style="margin-bottom: 20px;">
            <h4 style="color: #28a745; margin-bottom: 10px;">⬆️ 综合表现前五</h4>
            <table class="data-table">
                <thead>
                    <tr>
                        <th>排名</th>
                        <th>评估对象</th>
                        <th>类型</th>
                        <th>综合得分</th>
                        <th>主要优势</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in data.multi_dimension_rankings.top_performers %}
                    <tr>
                        <td>{{ loop.index }}</td>
                        <td>{{ item.name }}</td>
                        <td>{{ item.type }}</td>
                        <td class="highlight-good">{{ item.score | round(1) }}分</td>
                        <td>{{ item.advantage }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

        {% if data.multi_dimension_rankings.bottom_performers %}
        <div>
            <h4 style="color: #dc3545; margin-bottom: 10px;">⬇️ 需要改进的对象</h4>
            <table class="data-table">
                <thead>
                    <tr>
                        <th>排名</th>
                        <th>评估对象</th>
                        <th>类型</th>
                        <th>综合得分</th>
                        <th>主要问题</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in data.multi_dimension_rankings.bottom_performers %}
                    <tr>
                        <td>倒数第{{ loop.index }}</td>
                        <td>{{ item.name }}</td>
                        <td>{{ item.type }}</td>
                        <td class="highlight-bad">{{ item.score | round(1) }}分</td>
                        <td>{{ item.issue }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        {% endif %}
        {% else %}
        <div class="no-data">暂无排名数据</div>
        {% endif %}
    </div>
</div>

<!-- AI分析内容 -->
<div class="section">
    <div class="section-title">🤖 智能分析结论</div>
    <div class="section-content">
        {% if data.content_sections %}
            {% for section_title, content in data.content_sections.items() %}
            <div style="margin-bottom: 20px;">
                <h4 style="color: #1f4e79; margin-bottom: 12px; border-bottom: 1px solid #e0e0e0; padding-bottom: 8px;">{{ section_title }}</h4>
                <div style="text-align: justify; line-height: 1.8; margin-top: 12px;">
                    {{ content | safe }}
                </div>
            </div>
            {% endfor %}
        {% else %}
        <div class="no-data">AI分析内容生成中...</div>
        {% endif %}
    </div>
</div>

<!-- 多维度优化建议 -->
<div class="section">
    <div class="section-title">💡 多维度优化建议</div>
    <div class="section-content">
        <div class="success">
            <h4>综合优化建议</h4>
            <ul class="report-list">
                {% if data.dimension_overview and data.dimension_overview.overall_score < 0.8 %}
                <li><strong>提升综合表现：</strong>当前综合得分为 {{ (data.dimension_overview.overall_score * 100) | round(1) }}分，建议从以下维度进行优化。</li>
                {% endif %}
                
                {% if data.region_dimension %}
                <li><strong>区域均衡发展：</strong>加强各区域间的协调配合，缩小区域间效率差距。</li>
                {% endif %}
                
                {% if data.project_dimension %}
                <li><strong>项目精细化管理：</strong>针对不同项目特点制定差异化管理策略。</li>
                {% endif %}
                
                {% if data.device_type_dimension %}
                <li><strong>设备配置优化：</strong>根据设备类型性能特点，优化设备配置和使用策略。</li>
                {% endif %}
                
                {% if data.time_dimension %}
                <li><strong>时间资源管理：</strong>合理安排工作时间，提高峰值时段利用率。</li>
                {% endif %}
                
                <li><strong>数据驱动决策：</strong>建立多维度监控体系，实现基于数据的精准管理。</li>
                <li><strong>持续改进机制：</strong>定期进行多维度分析，建立持续改进的管理循环。</li>
            </ul>
        </div>
    </div>
</div>
{% endblock %}